#pragma once
#include <iostream>
#include <unistd.h>
#include <sys/epoll.h>
#include "Util.hpp"
#include "Comm.hpp"
static const int gsize = 128;
class Epoller
{
    public:
        Epoller(){
            _epfd = epoll_create(gsize);
            if(_epfd < 0)
            {
                std::cout << "Epoll Create Error!" ;
                exit(EPOLL_CREATE_ERROR);
            }
            std::cout << _epfd << std::endl;
            DLOG("Epoll Create Success!");
        }
        ~Epoller(){
            if(_epfd >= 0)
            {
                close(_epfd);
            }
        }
        bool AddEvent(int fd , uint32_t event)
        {
            struct epoll_event ev;
            ev.events = event;
            ev.data.fd = fd;
            int n = epoll_ctl(_epfd,EPOLL_CTL_ADD,fd,&ev);
            if(n < 0)
            {
                return false; 
            }
            return true;
        }
        int Wait(struct epoll_event revs[],int num , int timeout)
        {
            int n = epoll_wait(_epfd,revs,num,timeout);
            return n;
        }

    private:
        int _epfd;
};